home *** CD-ROM | disk | FTP | other *** search
- Path: peer-news.britain.eu.net!demon!thesett.demon.co.uk
- From: Andy@thesett.demon.co.uk (Andy Goodwin)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: New printf - like function, is it possible?
- Date: Fri, 02 Feb 1996 17:08:31 GMT
- Message-ID: <31124386.1286150@news.demon.co.uk>
- References: <4eqb3a$2r5@pan.otol.fi>
- NNTP-Posting-Host: thesett.demon.co.uk
- X-NNTP-Posting-Host: thesett.demon.co.uk
- X-Newsreader: Forte Agent .99c/16.141
-
- On 1 Feb 1996 12:18:50 GMT, tkes@rhea.otol.fi (Timo Sakari) wrote:
-
- >
- >Hi!
- >
- >Do you C-gurus have any solutions to this problem?
- >
- >I am programming under MS Windows 3.1 (this is NOT an OS spesific
- >question!)and I would like to create
- >some kind of modified print function, which syntax should be something
- >like normal printf; because in Windows printf can't be used, everything
- >printed to screen has to come through message boxes etc, and before
- >displaying anything, the string to displayed has to be formed. I have
- >created my own printing function, which wants parameters string and winID
- >to know where to put that string, something like this:
- >
- >sprintf(printStr, "some sfuff, variables %d, %f, etc", var1, var2);
- >PrintToWin(DEBUG_WIN_1, printStr);
- >
- >However, I want to write a "better" printing function, where string to be
- >formed doesn't need to be formatted first, it can be displayed and formed
- >at the same time in the same syntax like printf, something like these:
- >
- >PrintToWin(DEBUG_WIN_1, "some stuff etc, %d, %f, %s, var1, var2, str1);
- >PrintToWin(OTHER_WIN, "anything that printf accepts");
- >
- >So I want to print almost anything with this function without having
- >to write many functions to different argument types/number of arguments.
- >This should be possible in C++ (is it?), but is it possible in C ?
- >Can this be achieved by using void pointers and macros etc., or should
- >I give up and don't waste my time on this?
- >
- >Any help would be greatly appreciated. Thanks.
- >
- >
- >
- >--
- > Timo Sakari phone: (981) 5306 070
- > Haapanatie 2 D 408 email: tkes@rhea.otol.fi
- > 90150 OULU WWW: http://www.otol.fi/~tkes/
- > FINLAND
-
- Look at the folling functions in your C documentation
- type va_arg( va_list arg_ptr, type );
-
- void va_end( va_list arg_ptr );
-
- void va_start( va_list arg_ptr ); (UNIX version)
- void va_start( va_list arg_ptr, prev_param ); (ANSI)
-
- Microsoft C gives an example of how to average 'n' integers
-
- Your function would have to be prototyped as :-
-
- void PrintToWin( int, const char *, ... ) ;
-
- You could then use the vsprintf function after generating a va_list
- variable and temporary buffer
-
- eg
-
- vsprintf( buffer, const char *format, va_list argptr );
-
-